﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace kwzx
{
    public partial class dwForm : Form
    {
        public const short ORDER_OK = 0x30;

        public dwForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int mycnn = dwkey.TCPCONNECT("192.168.5.10");
            if (mycnn == 48)
            {
                int CardID = 0;
                //KeyType类型          Gname宾客姓名,GID:,证件号      RoomName:房间名称         卡片有效期   KStart,  KEnd   CardID:返回的卡号
                int kh = dwkey.TCP_KEY(00, "初亮", "654222198110304719", "A101:A103:A102", "2013-01-01 12:12:12", "2020-01-01 12:12:12", ref CardID);
                dwkey.TCPDISCONNECT();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int mycnn = dwkey.TCPCONNECT("192.168.5.10");
            if (mycnn == 48)
            {
                dwkey.PChar pc = new dwkey.PChar();


                byte KeyType = 00;

                kwzx.dwkey.PChar GName = new dwkey.PChar();
                kwzx.dwkey.PChar GID = new dwkey.PChar(); ;
                kwzx.dwkey.PChar RoomName = new dwkey.PChar(); ;
                kwzx.dwkey.PChar KStart = new dwkey.PChar(); ;
                kwzx.dwkey.PChar KEnd = new dwkey.PChar(); ;

                //string GName = "";
                //string GID = "";
                //string RoomName = "";
                //string KStart = "";
                //string KEnd = "";

                int CardID = 0;
                byte myresult;
                //string sTemp;
                try
                {
                    //myresult = dwkey.TCP_CHECKCARD(ref KeyType, ref GName, ref GID, ref RoomName, ref KStart, ref KEnd, ref CardID);
                    myresult = dwkey.TCP_CHECKCARD(ref KeyType, ref GName, ref GID, ref RoomName, ref KStart, ref KEnd, ref CardID);
                    dwkey.TCPDISCONNECT();
                    string GName1 = new string(GName.MyGetData).Replace("\0", "");
                    string GID1 = new string(GID.MyGetData).Replace("\0", "");
                    string KStart1 = new string(KStart.MyGetData).Replace("\0", "");
                    string KEnd1 = new string(KEnd.MyGetData).Replace("\0", "");
                    string RoomName1 = new string(RoomName.MyGetData).Replace("\0", "");

                    this.textBox1.Text = CardID.ToString() + "\r\n" + GName1 + "\r\n" + GID1 + "\r\n" + KStart1 + "\r\n" + KEnd1 + "\r\n" + RoomName1 + "\r\n";
                    if (myresult == ORDER_OK)
                    {
                        //MessageBox.Show(CardID.ToString());
                        //MessageBox.Show(GName.MyGetData.ToString());
                        //MessageBox.Show(GID.MyGetData.ToString());
                        //MessageBox.Show(KStart.MyGetData.ToString());
                        //MessageBox.Show(KEnd.MyGetData.ToString());
                        //MessageBox.Show(RoomName.MyGetData.ToString());
                    }
                    else
                    {
                        MessageBox.Show(myresult.ToString() + "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("00");
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int mycnn = dwkey.TCPCONNECT("192.168.5.10");
            if (mycnn == 48)
            {
                dwkey.TCP_CHECKOUT("A102", true);
                dwkey.TCPDISCONNECT();
            }
        }
    }
}
